import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import lazyPlugin from 'vue3-lazy'
import loadingDirective from '@/components/base/loading/directive'
import noResultDirective from '@/components/base/no-result/directive'
import { load, saveAll } from '@/assets/js/array-store'
import { FAVORITE_KEY, PLAY_KEY } from '@/assets/js/constant'
import { processSongs } from '@/service/song'

// 引入全局样式文件
import '@/assets/scss/index.scss'

loadSetNewUrl(FAVORITE_KEY, 'setFavoriteList')
loadSetNewUrl(PLAY_KEY, 'setPlayHistory')

function loadSetNewUrl(key, commitKey) {
  const songs = load(key)
  if (songs.length > 0) {
    processSongs(songs).then((song) => {
      store.commit(commitKey, song)
      saveAll(song, key)
    })
  }
}

createApp(App).use(store).use(router).use(lazyPlugin, {
  loading: require('@/assets/images/loading.gif'),
  error: require('@/assets/images/default.png')
}).directive('loading', loadingDirective).directive('no-result', noResultDirective).mount('#app')
